home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Draw / TOvalObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-17  |  5.5 KB  |  218 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        TOvalObj.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1992-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* See the files "=How to write your app" and "=Using TreeObj.c" for information
  20. ** on this function. */
  21.  
  22. /* This file implements the messages for the oval object.  Many of the messages
  23. ** can be handled by the rect object, as they deal with a rect structure.  Only
  24. ** a few of them are oval-specific. */
  25.  
  26. /* It would seem that you would want a custom hit-test message handler here, but
  27. ** the rect object first checks to see if the hit is within the bounding box of
  28. ** the object, and if so, it then calls the object to return the region.  This
  29. ** allows the rect object to generically handle hit-testing. */
  30.  
  31.  
  32.  
  33. /*****************************************************************************/
  34.  
  35.  
  36.  
  37. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  38. #include "App.protos.h"        /* Get the prototypes for the application.        */
  39.  
  40. #ifndef __OSEVENTS__
  41. #include <OSEvents.h>
  42. #endif
  43.  
  44. #ifndef __OSUTILS__
  45. #include <OSUtils.h>
  46. #endif
  47.  
  48. #ifndef __QUICKDRAW__
  49. #include <Quickdraw.h>
  50. #endif
  51.  
  52. #ifndef __STRING__
  53. #include <String.h>
  54. #endif
  55.  
  56. #ifndef __TREEOBJ2__
  57. #include "TreeObj2.h"
  58. #endif
  59.  
  60. #ifndef __UTILITIES__
  61. #include "Utilities.h"
  62. #endif
  63.  
  64.  
  65.  
  66. #pragma segment DrawObjects
  67. long    TOvalObj(TreeObjHndl hndl, short message, long data)
  68. {
  69.     Rect        rct;
  70.     RgnHandle    rgn, accumRgn;
  71.     short        h, w;
  72.     RGBColor    rgb, rgb2;
  73. #if VH_VERSION
  74.     char        *cptr;
  75. #endif
  76.  
  77.     switch (message) {
  78.         case INITMESSAGE:
  79.         case FREEMESSAGE:
  80.         case COPYMESSAGE:
  81.         case UNDOMESSAGE:
  82.         case CONVERTMESSAGE:
  83.         case FREADMESSAGE:
  84.         case FWRITEMESSAGE:
  85.         case HREADMESSAGE:
  86.         case HWRITEMESSAGE:
  87.         case HITTESTMESSAGE:
  88.         case GETOBJRECTMESSAGE:
  89.         case SETOBJRECTMESSAGE:
  90.         case SECTOBJRECTMESSAGE:
  91.         case GETBBOXMESSAGE:
  92.         case CLICKMESSAGE:
  93.         case KEYMESSAGE:
  94.         case SETSELECTMESSAGE:
  95.         case GETSELECTMESSAGE:
  96.         case SIZEMESSAGE:
  97.         case COMPAREMESSAGE:
  98.             return(TRectObj(hndl, message, data));
  99.             break;
  100.  
  101.         case GETRGNMESSAGE:
  102.             rgn      = NewRgn();
  103.             accumRgn = (RgnHandle)data;
  104.             if (accumRgn)
  105.                 if (GetHandleSize((Handle)accumRgn) > 10000)
  106.                     return((long)rgn);
  107.             OpenRgn();
  108.             rct = mDerefOval(hndl)->oval;
  109.             FrameOval(&rct);
  110.             CloseRgn(rgn);
  111.             if (accumRgn)
  112.                 UnionRgn(rgn, accumRgn, accumRgn);
  113.             return((long)rgn);
  114.             break;
  115.  
  116.         case DRAWMESSAGE:
  117.             rct = mDerefOval(hndl)->oval;
  118.             h   = mDerefCommon(hndl)->penHeight;
  119.             w   = mDerefCommon(hndl)->penWidth;
  120.             PenSize(w, h);
  121.             switch (data) {
  122.                 case DRAWOBJ:
  123.                     if (gQDVersion)
  124.                         GetForeColor(&rgb);
  125.                     ForeColor(whiteColor);
  126.                     if (gQDVersion) {
  127.                         rgb2 = mDerefOval(hndl)->contentColor;
  128.                         RGBForeColor(&rgb2);
  129.                     }
  130.                     PaintOval(&rct);
  131.                     ForeColor(blackColor);
  132.                     if (gQDVersion) {
  133.                         rgb2 = mDerefOval(hndl)->borderColor;
  134.                         RGBForeColor(&rgb2);
  135.                     }
  136.                     FrameOval(&rct);
  137.                     if (gQDVersion)
  138.                         RGBForeColor(&rgb);
  139.                     break;
  140.                 case ERASEOBJ:
  141.                     EraseOval(&rct);
  142.                     break;
  143.                 case DRAWSELECT:
  144.                     TRectObj(hndl, message, data);
  145.                     break;
  146.                 case DRAWGHOST:
  147.                     PenMode(patXor);
  148.                     FrameOval(&rct);
  149.                     break;
  150.                 case DRAWMASK:
  151.                     FillOval(&rct, (ConstPatternParam)&qd.black);
  152.                     break;
  153.             }
  154.             PenNormal();
  155.             break;
  156.  
  157.         case PRINTMESSAGE:
  158.             TOvalObj(hndl, DRAWMESSAGE, DRAWOBJ);
  159.             break;
  160.  
  161. #if VH_VERSION
  162.         case VHMESSAGE:
  163.             cptr = ((VHFormatDataPtr)data)->data;
  164.             ccatchr(cptr, 13, 2);
  165.             ccat   (cptr, "$10: TOvalObj:");
  166.             ccatchr(cptr, 13, 1);
  167.             ccat   (cptr, "  $00: selected     = ");
  168.             ccatdec(cptr, mDerefOval(hndl)->selected);
  169.             ccatchr(cptr, 13, 1);
  170.             rct = mDerefOval(hndl)->oval;
  171.             ccat      (cptr, "  $02: oval         = ($");
  172.             ccatpadhex(cptr, 0, 4, 4, rct.top);
  173.             ccat      (cptr, ",$");
  174.             ccatpadhex(cptr, 0, 4, 4, rct.left);
  175.             ccat      (cptr, ",$");
  176.             ccatpadhex(cptr, 0, 4, 4, rct.bottom);
  177.             ccat      (cptr, ",$");
  178.             ccatpadhex(cptr, 0, 4, 4, rct.right);
  179.             ccat      (cptr, ")");
  180.             ccatchr   (cptr, 13, 1);
  181.             ccat      (cptr, "  $0A: penHeight    = ");
  182.             ccatdec   (cptr, mDerefOval(hndl)->penHeight);
  183.             ccatchr   (cptr, 13, 1);
  184.             ccat      (cptr, "  $0C: penWidth    = ");
  185.             ccatdec   (cptr, mDerefOval(hndl)->penWidth);
  186.             ccatchr   (cptr, 13, 1);
  187.             ccat      (cptr, "  $0E: borderColor  = ($");
  188.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.red);
  189.             ccat      (cptr, ",$");
  190.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.green);
  191.             ccat      (cptr, ",$");
  192.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.blue);
  193.             ccat      (cptr, ")");
  194.             ccatchr   (cptr, 13, 1);
  195.             ccat      (cptr, "  $1$: content      = ($");
  196.             ccatdec   (cptr, mDerefOval(hndl)->content);
  197.             ccatchr   (cptr, 13, 1);
  198.             ccat      (cptr, "  $16: contentColor = ($");
  199.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.red);
  200.             ccat      (cptr, ",$");
  201.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.green);
  202.             ccat      (cptr, ",$");
  203.             ccatpadhex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.blue);
  204.             ccat      (cptr, ")");
  205.             return(true);
  206.             break;
  207. #endif
  208.  
  209.         default:
  210.             break;
  211.     }
  212.  
  213.     return(noErr);
  214. }
  215.  
  216.  
  217.  
  218.